package main

import (
  "fmt"
  "encoding/json"
)

type Node struct{
  Name string
  Type string
  ParentId string
  Children []Node
}

var q *[]Node

func main() {
  b := []byte(`{
    "name":"1-0-0",
    "type":"1",
    "id":"route-A",
    "children":[{
      "name":"12-44-5-5-6",
      "type":"5",
      "parentId":"route-A",
      "id":"route-B",
      "children":[{
        "name":"dw",
        "type":"9" ,
        "parentId":"route-B",
        "id":"route-C"
      }]
    }, {
      "name":"zhq",
      "type":"8",
      "parentId":"route-A",
      "id":"route-B"
    }, {
      "name":"xjp",
      "type":"8",
      "parentId":"route-A",
      "id":"route-B",
      "children":[]
    }]
  }`)


  var f Node
  err := json.Unmarshal(b, &f)
  if err != nil {
    fmt.Println("出错了")
  }
  var node1 Node
  node1.Name = "中国"

  
  *q = append(*q, node1)

  var bo bool
  bo = one2(&f, "route-A", "xjp")
  
  fmt.Println(bo)
  fmt.Println(f)
}

func one(z *[]Node, id string, name string) bool {
  for k,v := range *z {
    v = v
    if one2(&((*z)[k]), id, name) == true {
      return true
    }
  }
  return false
}

func one2(z *Node, id string, name string) bool {
  if z.ParentId == id && z.Name == name {
    return true
  } else if z.Children != nil {
    b := one(&z.Children, id, name)
    if b == true && q == nil {
      q = &z.Children
    }
    return b;

  }
  return false
}
